#define _CRT_SECURE_NO_WARNINGS 1


#include<vector>
#include<map>
#include<iostream>

using namespace std;

int subarraysDivByK(vector<int>& nums, int k)
{
    map<int, int> hash;
    hash[0] = 1;
    int sum = 0, count = 0;
    for (auto& e : nums)
    {
        sum += e;
        int val = (sum % k + k) % k;
        if (hash.count(val))
        {
            count += hash[val];
        }
        hash[val]++;
    }
    return count;
}